﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CARE.Web.db;
using CARE.GraphProviderServiceReference;

namespace CARE.Views
{
    public partial class DatabaseSocialNetworkWindow : ChildWindow
    {
        private GraphProviderServiceClient graphProvider;
        private String GraphML = String.Empty;

        public DatabaseSocialNetworkWindow()
        {
            InitializeComponent();
            graphProvider = new GraphProviderServiceClient();
            graphProvider.netToGraphmlCompleted += new EventHandler<netToGraphmlCompletedEventArgs>(graphProvider_netToGraphmlCompleted);
        }

        void graphProvider_netToGraphmlCompleted(object sender, netToGraphmlCompletedEventArgs e)
        {
            OKButton.IsEnabled = true;
            GraphML = e.Result;
        }

        public String SocialNetwork
        {
            get { return GraphML; }

        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void netDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void networksBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (networksBox.SelectedItem != null)
            {
                OKButton.IsEnabled = false;
                graphProvider.netToGraphmlAsync(((Net)networksBox.SelectedItem).netName);
            }
        }
    }
}

